﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using Npgsql;
using System.Reflection.Metadata;
using Microsoft.Extensions.Configuration;

using Bogus;
using FreeSql;
using Newtonsoft.Json;

using StackExchange.Redis;

using Microsoft.EntityFrameworkCore.Storage;
string connectionString = "Server=519278e4v.vicp.fun;Port=56119;User Id=zhangyongli;Password=supermap@123;Database=yu;";
NpgsqlConnection conn = new NpgsqlConnection(connectionString);




// 连接到garnet，这里要写死端口
//ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("192.168.5.121:3278");

//// Get the database (by default, it's DB 0)
//StackExchange.Redis.IDatabase db = redis.GetDatabase();

//// 存入数据
//db.StringSet("key1", "Hello, Garnet!");

//// 读取数据
//string value = db.StringGet("key1");
//Console.WriteLine(value); // Output: Hello, Redis!

//// Increment a value
//db.StringIncrement("counter1");
//long counterValue = (long)db.StringGet("counter1");
//Console.WriteLine(counterValue); // Output: 1

//Console.WriteLine("运行结束");
//Console.ReadLine();




// 配置连接字符串
// connectionString = "Host=192.168.5.121; Port=15400; Username=zhangyongli;Password=supermap@123;Database=yu";

// 创建连接对象
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
    try
    {
        // 打开连接
        connection.Open();
        Console.WriteLine("成功连接到 高斯 数据库！");

        // 创建命令对象
        string query = "select id, name from student s ";
        using (NpgsqlCommand command = new NpgsqlCommand(query, connection))
        {
            // 执行查询并读取结果
            using (NpgsqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    int id = reader.GetInt32(0);
                    string name = reader.GetString(1);
                    Console.WriteLine($"ID: {id}, Name: {name}");
                }
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("连接或查询过程中发生错误: " + ex.Message);
    }
}
